using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace AcronymPlugin
{
    public partial class frmMain : Form
    {
        string strText = "";

        public frmMain(string text)
        {
            InitializeComponent();
            this.Controls.Add(txbxAbbr);
            this.Controls.Add(txbxAcronym);
            this.Controls.Add(txbxLink);
            txbxLink.Text = text;
            txbxAbbr.KeyPress += new KeyPressEventHandler(KeyPressed);
            txbxAcronym.KeyPress +=new KeyPressEventHandler(KeyPressed);
            txbxLink.KeyPress += new KeyPressEventHandler(KeyPressed);

        }

        void KeyPressed(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Escape)
            {
                this.Close();
            }
            if (e.KeyChar == (char)Keys.Enter)
            {
                btnInsert_Click(this, null);
            }
        }

        private void btnInsert_Click(object sender, EventArgs e)
        {
            string link = "";

            if (txbxLink.Text != "" && (txbxAcronym.Text != "" || txbxAbbr.Text != ""))
            {
                link = txbxLink.Text;

                if (txbxAbbr.Text != "" && txbxAcronym.Text != "")
                {
                    MessageBox.Show("Please use only abbr or acronym.", "Big Fat Hairy Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                if (txbxAbbr.Text != "" && txbxAcronym.Text == "")
                {
                    strText = string.Format("<abbr title=\"{0}\">{1}</abbr>", txbxAbbr.Text, link);

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                if (txbxAcronym.Text != "" && txbxAbbr.Text == "")
                {
                    strText = string.Format("<acronym title=\"{0}\">{1}</acronym>", txbxAcronym.Text, link);
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }

            }
            else
            {
                MessageBox.Show("You haven't put anything in the text fields.", "Big Fat Hairy Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


        }
                
        public string getText
        {
            get { return strText; }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}